from selenium.webdriver.common.by import By

from page.focus_project_page import FocusProjectPage
from common.page import XPATH
import time as t


class FocusAttendancePage(FocusProjectPage):

    def get_qr(self):  # 管理员获取考勤二维码，保存至相册
        self.find_element(XPATH,"//XCUIElementTypeStaticText[contains(@label,'今天')]").click()
        t.sleep(2)
        # self.find_static_text(string='已出勤',contains_flag=1).click()
        self.find_static_text(string='班次1', contains_flag=1).click()
        self.find_button("more").click()
        self.find_button('查看二维码').click()
        t.sleep(2)
        self.find_button('保存到本地').click()
        t.sleep(2)
        self.find_button(string="代签",contains_flag=1).click()
        self.find_static_text(string="已出勤",contains_flag=1).click()
        self.swipe_dr("down")
        t.sleep(1)
        self.find_button(string="返回",contains_flag=1).click()
        self.find_button(string="返回", contains_flag=1).click()
        self.find_button(string="数学班", contains_flag=1).click()


    def submit_with_qr(self):  # 使用二维码进行签到，不需进入考勤工具
        self.find_button(string="attendance scan icon", contains_flag=1).click()
        self.find_button(string='相册',contains_flag=1).click()
        self.get_frame_center_and_click(
            self.find_elements(XPATH, "//XCUIElementTypeCell/XCUIElementTypeOther/XCUIElementTypeImage")[-1], # 选取倒数第二张
            flag=0
        )
        self.find_button('完成').click()
        self.find_button('签到').click()
        self.find_button('我知道了').click()
        self.find_button(string="返回",contains_flag=1).click()
        self.find_button(string="返回", contains_flag=1).click()
        self.find_button(string="数学班", contains_flag=1).click()